package com.googlecode.sc2dm.annotations;

import android.content.Context;
import android.content.Intent;
import com.googlecode.sc2dm.annotations.types.AnnotatedObject;
import com.googlecode.sc2dm.register.util.AnnotatedTwoArgs;
import junit.framework.TestCase;

import java.lang.reflect.Method;

/**
 * @Author Jarle Hansen (jarle@jarlehansen.net)
 * Created: 12:57 PM - 9/22/11
 */
public class AnnotatedObjectTest extends TestCase {
    private TestAnnotatedObject annotatedObject;

    public void setUp() {
        Class<?> clazz = AnnotatedTwoArgs.class;

        Method[] methods = clazz.getDeclaredMethods();
        Method method = null;
        // Only use reg()
        for (Method m : methods) {
            if (m.toString().contains("reg"))
                method = m;
        }

        annotatedObject = new TestAnnotatedObject(clazz, method);
    }

    public void testNewInstance() {
        Object o = annotatedObject.instance();
        assertTrue(o instanceof AnnotatedTwoArgs);
    }

    


    /**
     * Makes it possible to test the abstract AnnotatedObject class
     */
    private static class TestAnnotatedObject extends AnnotatedObject {

        public TestAnnotatedObject(Class<?> clazz, Method method) {
            super(clazz, method);
        }

        @Override
        public Object instance() {
            return super.instance();
        }

        @Override
        public Object[] buildArgs(Context context, String msg) {
            return super.buildArgs(context, msg);
        }
    }
}
